package com.micro.Controller;


import com.micro.mapper.UserMapper;
import com.micro.pojo.LoginUser;
import com.micro.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class LoginController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @RequestMapping(value = "login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    @RequestMapping(value = "register", method = RequestMethod.GET)
    public String register() {
        return "register";
    }



    @ResponseBody
    @PostMapping("/register1")
    public Result registerUser(String username,String password){
        LoginUser loginUser = new LoginUser();
        loginUser.setUsername(username);
        loginUser.setPassword(bCryptPasswordEncoder.encode(password));
        loginUser.setEnableds(1);
        int i = userMapper.insertUUID(loginUser);
        return new Result().success("注册成功！");
    }

}
